local xianjue = fk.CreateSkill{
  name = "wk_heg__xianjue",
}

Fk:loadTranslationTable{
  ["wk_heg__xianjue"] = "先决",
  [":wk_heg__xianjue"] = "每回合限一次，你可以将所有暗置牌当一张明置牌中的任意基本牌或非延时锦囊牌使用（不能选择自己为目标）。",
}

local H = require "packages/ol_hegemony/util"
local HG = require "packages/new_heg_diy_my/util"

xianjue:addEffect("viewas", {
  pattern = ".",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("bt")
    local able_names = {}
    for _, value in ipairs(HG.getShownCards(player)) do
      local c = Fk:getCardById(value)
      if table.contains(all_names, c.name) and (not Fk.currentResponsePattern or Exppattern:Parse(Fk.currentResponsePattern):match(c)) then
        table.insertIfNeed(able_names, c.name)
      end
    end
    able_names = player:getViewAsCardNames(xianjue.name, able_names, HG.getHiddenCards(player))
    return UI.CardNameBox {
      choices = able_names,
      default_choice = "AskForCardsChosen"
    }
  end,
  card_filter = Util.FalseFunc,
  view_as = function (self, player)
    if Fk.all_card_types[self.interaction.data] == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(HG.getHiddenCards(player))
    card.skillName = xianjue.name
    return card
  end,
  enabled_at_play = function(self, player)
    local all_names = Fk:getAllCardNames("bt")
    local able_names = {}
    for _, value in ipairs(player:getCardIds("h")) do
      local c = Fk:getCardById(value)
      if c:getMark(MarkEnum.ShownCards)>0 and table.contains(all_names,c.name) and (not Fk.currentResponsePattern or Exppattern:Parse(Fk.currentResponsePattern):match(c)) then
        table.insertIfNeed(able_names,c.name)
      end
    end
    able_names = player:getViewAsCardNames(xianjue.name, able_names, HG.getHiddenCards(player))
    return player:usedSkillTimes(xianjue.name, Player.HistoryTurn) == 0 and #able_names > 0 and 
      table.find(player:getCardIds("h"), function (element, index, array) return Fk:getCardById(element):getMark(MarkEnum.ShownCards) == 0 end)
  end,
  enabled_at_response = function (self, player, response)
    return not response and player:usedSkillTimes(xianjue.name, Player.HistoryTurn) == 0 
     and table.find(player:getCardIds("h"), function (cid) return Fk:getCardById(cid):getMark(MarkEnum.ShownCards) > 0 
     and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:getCardById(cid)) end) 
     and table.find(player:getCardIds("h"), function (cid) return Fk:getCardById(cid):getMark(MarkEnum.ShownCards) == 0 end)
  end
})

xianjue:addEffect("prohibit", {
  is_prohibited = function(self, from, to, card)
    return card and from == to and from:hasSkill(self) and table.contains(card.skillNames, "wk_heg__xianjue")
  end,
})

return xianjue